package com.grom.dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import com.dispacher.config.GlobalConfig;

public class DatabaseDao {

	private static final String userName = GlobalConfig.getProperty("jdbc.username");
	private static final String password = GlobalConfig.getProperty("jdbc.password");
	private static Connection conn;
	static {
		try {
			Class.forName("com.mysql.jdbc.Driver");
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
	}

	public static Connection getConnection() {
		try {
			if (conn == null || conn.isClosed()) {
				conn = DriverManager.getConnection(
						"jdbc:mysql://localhost:3306/gcms?useUnicode=true&characterEncoding=UTF-8", userName, password);
			}
			return conn;
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return null;
	}

	public static void main(String[] args) {
		System.out.println(getConnection());
	}
}
